package com.zkthink.ceres.applet.order.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zkthink.ceres.applet.common.domin.PageDate;
import com.zkthink.ceres.applet.order.domain.entity.AppletServerOrder;
import com.zkthink.ceres.applet.order.domain.vo.MyServerOrderListVo;
import com.zkthink.ceres.applet.order.domain.vo.OrderListVo;
import com.zkthink.ceres.applet.order.domain.vo.ServerOrderListVo;
import com.zkthink.clh.order.vo.MyqianbaodetailsVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**

@Author cmz
@Date 2024-04-30 9:32
*/
public interface AppletServerOrderMapper extends BaseMapper<AppletServerOrder> {

    Page<ServerOrderListVo> selectServerByPageAndMid(@Param("page")Page<ServerOrderListVo> page,@Param("mid") Long mid);

    List<MyqianbaodetailsVo> smyqianbao(Long mid);

    Page<OrderListVo> selectServerOrderListByPage(@Param("page") Page<OrderListVo> page,@Param("mid") Long mid);

    Page<OrderListVo> selectWxServerOrderListByPage(@Param("page") Page<OrderListVo> page,@Param("mid") Long mid);

    Page<MyServerOrderListVo> selectByMid(@Param("page") Page<MyServerOrderListVo> page,@Param("mid") Long mid);

    @Select("select ifnull(sum(ifnull(pay_sum,0)-ifnull(cut_amount,0)),0) from applet_server_order aso where DATE(aso.pay_time) = CURDATE() and aso.store_id = #{storeId}")
    BigDecimal selectByToDayIncomeByStoreId(Long storeId);

    @Select("select ifnull(sum(ifnull(pay_sum,0)-ifnull(cut_amount,0)),0) from applet_server_order aso where aso.store_id = #{storeId} and aso.pay_time is not null")
    BigDecimal selectByCumulativeIncomeByStoreId(Long storeId);

    @Select("select ifnull(sum(ifnull(pay_sum,0)-ifnull(cut_amount,0)),0) from applet_server_order aso where DATE(aso.pay_time) = CURDATE() and aso.vehicles_id = #{vehiclesId}")
    BigDecimal selectByToDayIncomeByVehiclesId(Long vehiclesId);

    @Select("select ifnull(sum(ifnull(pay_sum,0)-ifnull(cut_amount,0)),0) from applet_server_order aso where aso.vehicles_id = #{vehiclesId} and pay_time is not null")
    BigDecimal selectByCumulativeIncomeByVehiclesId(Long vehiclesId);

    Page<OrderListVo> selectAllOrderByorderStatusAndStoreIdOrVehiclesId(@Param("page") Page<OrderListVo> page,@Param("serverOrderStatus") Integer serverOrderStatus,@Param("productOrderStatus") Integer productOrderStatus,@Param("storeId") Long storeId,@Param("vehiclesId") Long vehiclesId,@Param("payStatus") Integer payStatus);

    /**
     * 根据传入的id查询数据(传其一)
     * @param storeId 店铺id
     * @param vehiclesId 理疗车id
     * @return
     */
    List<Map<String, Object>> selectIncomeDetailByStoreId(@Param("storeId") Long storeId,@Param("vehiclesId")Long vehiclesId,@Param("type") Integer type);
}